% convert from decimal to binary array
function [bin_arr] = encode2binary(dec)
bin_arr = [];
temp = dec;
while temp ~= 0
    m = mod(temp,2);
    bin_arr = [m bin_arr];
    temp = fix(temp/2);
end